package main.examination.NetEase;

import java.util.HashMap;
import java.util.Scanner;

/** 给出一颗二叉树，问两个子节点都是叶子节点的节点的数量。 */
public class ex1 {

    private static int res;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().split(" ")[1]);
        if (n == 0) {
            return;
        }
        TreeNode root = new TreeNode(1);
        HashMap<Integer, TreeNode> map = new HashMap<>();
        map.put(1, root);
        for (int i = 0; i < n; i++) {
            String[] line = sc.nextLine().split(" ");
            int val = Integer.parseInt(line[2]);
            TreeNode node = new TreeNode(val);
            map.put(val, node);
            if ("left".equals(line[1])) {
                map.get(Integer.parseInt(line[0])).left = node;
            } else {
                map.get(Integer.parseInt(line[0])).right = node;
            }
        }
        solution(root);
        System.out.println(res);
    }

    private static boolean solution(TreeNode root) {
        if (root.left == null && root.right == null) {
            return true;
        } else if (root.left == null) {
            return solution(root.right);
        } else if (root.right == null) {
            return solution(root.left);
        }
        boolean left = solution(root.left);
        boolean right = solution(root.right);
        if (left && right) {
            ++res;
        }
        return false;
    }

    private static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
}
